﻿using System;
using System.Linq;
using System.Activities;
using System.Activities.Statements;
using System.ServiceModel;

using System.Collections.Generic;


namespace MyNet.QueryWorkflow {


    using MyNet.WebServices;

    class Program {

        IMyNetDbService myNetDbAmericanService;
        IMyNetDbService myNetDbEuropeanService;
        IMyNetDbService myNetDbAsianService;


        public Program() {

            var baseAddress = "http://mynetprojectreloaded.cloudapp.net:8080";

            var americanServiceURI = baseAddress + "/MyNetDbServiceInAmerica.svc";
            var europeanServiceURI = baseAddress + "/MyNetDbServiceInEurope.svc";
            var asianServiceURI    = baseAddress + "/MyNetDbServiceInAsia.svc";

            myNetDbAmericanService = new ChannelFactory<IMyNetDbService>(
                new WSHttpBinding( "MyNetDbBinding" ),
                new EndpointAddress( americanServiceURI )
            ).CreateChannel();

            myNetDbEuropeanService = new ChannelFactory<IMyNetDbService>(
                new WSHttpBinding( "MyNetDbBinding" ),
                new EndpointAddress( europeanServiceURI )
            ).CreateChannel();

            myNetDbAsianService = new ChannelFactory<IMyNetDbService>(
                new WSHttpBinding( "MyNetDbBinding" ),
                new EndpointAddress( asianServiceURI )
            ).CreateChannel();

        } // constructor


        public void Run() {

            Dictionary<String, Object> input = new Dictionary<string, object> { 
                { "myNetDbAmericanService", myNetDbAmericanService },
                { "myNetDbEuropeanService", myNetDbEuropeanService },
                { "myNetDbAsianService", myNetDbAsianService }
            };

            Activity wf = new QueryWorkflowExample();
            WorkflowInvoker.Invoke( wf, input );
        
        } // method


        public void Init( String accessToken ) {

            myNetDbAmericanService.addFacebookUser( RegularFacebookUser.Javier, accessToken );
            myNetDbEuropeanService.addFacebookUser( RegularFacebookUser.Genoveva, accessToken );
            myNetDbAsianService.addFacebookUser( RegularFacebookUser.Epal, accessToken );
        
        } // method

        static void Main( string[] args ) {

            var accessToken = "AAACEdEose0cBAD8QxHUay6Vt2W0f1IbnEW9EBla9ZAesKelgVTNRvCKL5eW8tMGTEi4n50W40Be6ZAxo1FBtGpcedArISf6SuvWsb48AZDZD";

            var program = new Program();
           // program.Init( accessToken );
            program.Run();

        } // method

    } // class

}
